//package com.io.test;
//
//import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
//import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
//import org.junit.jupiter.api.Test;
//
//import java.io.*;
//import java.nio.ByteBuffer;
//import java.nio.channels.FileChannel;
//import java.util.Date;
//
///**
// * Created by 41579 on 2016/12/21.
// */
//public class testClass {
//    public void fun1() throws IOException {
//        PipedInputStream is = new PipedInputStream();
//        PipedOutputStream os = new PipedOutputStream();
//        is.connect(os);
//        Thread t = new Thread(new myRunable(os));
//        t.start();
////        byte[] bytes = new byte[1024];
////        while(is.read(bytes)>0){
////            System.out.println(new String(bytes));
////        }
//    }
//
//    public void fun2() throws Exception {
//        FileInputStream fis = new FileInputStream("H:\\git\\knowledge\\IO_NIO\\file\\test.txt");
//        FileOutputStream fos = new FileOutputStream("");
//        byte[] bytes = new byte[1024];
//        Thread t = new Thread(new myRunable2(fos));
//        t.start();
//        while (true) {
//            System.out.println("....");
//            fis.read(bytes);
//            System.out.println("1" + new String(bytes));
//        }
//    }
//
//    public void fun3() throws Exception {
//        ByteOutputStream bos = new ByteOutputStream(1);
//        while (true) {
//            bos.write("test".getBytes());
//            System.out.println("写完了");
//        }
//    }
//
//    public void fun4() throws Exception {
//        RandomAccessFile file = new RandomAccessFile("H:\\git\\knowledge\\IO_NIO\\file\\test.txt", "rw");
//        FileChannel fileChannel = file.getChannel();
//        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
//        //       byteBuffer.put("hello".getBytes());
////        byteBuffer.flip();
////        while(true) {
//        //写模式
//        fileChannel.read(byteBuffer);
//        System.out.println(byteBuffer.position());
//        System.out.println(byteBuffer.capacity());
//        System.out.println(byteBuffer.limit());
//        //读模式
//        byteBuffer.flip();
//        System.out.println(byteBuffer.position());
//        System.out.println(byteBuffer.capacity());
//        System.out.println(byteBuffer.limit());
////        }
////        byteBuffer.flip();
////        Thread.sleep(3000);
////        Thread t = new Thread(new Runnable() {
////            public void run() {
////                try {
////                    ByteBuffer byteBuffer2 = ByteBuffer.allocate(1024);
////                    RandomAccessFile file2 = new RandomAccessFile("H:\\git\\knowledge\\IO_NIO\\file\\test.txt", "rw");
////                    FileChannel fileChannel2 = file2.getChannel();
////                    fileChannel.read(byteBuffer2);
////                    byteBuffer2.flip();
////                    System.out.println(byteBuffer2.get());
////                } catch (Exception e) {
////                    e.printStackTrace();
////                }
////            }
////        });
////        t.start();
//    }
//
//    public void fun5() throws Exception {
//        RandomAccessFile file = new RandomAccessFile("H:\\git\\knowledge\\IO_NIO\\file\\test.txt", "rw");
//        RandomAccessFile file2 = new RandomAccessFile("H:\\git\\knowledge\\IO_NIO\\file\\test2.txt", "rw");
//        FileChannel fileChannel = file.getChannel();
//        FileChannel fileChannel2 = file2.getChannel();
//        fileChannel2.transferFrom(fileChannel,0,fileChannel.size());
//    }
//
//    @Test
//    public void funTest() throws Exception {
//        byte[] test1 = "张".getBytes("utf-8");
//        System.out.println(test1);
//
//        DataInputStream dis = new DataInputStream(System.in);
//        byte[] a = new byte[1024];
//        while(dis.read(a)>0){
//            System.out.println(new String(a));
//        }
//
//
//    }
//
//
//    public String chinaToUnicode(String str){
//        String result="";
//        for (int i = 0; i < str.length(); i++){
//            int chr1 = (char) str.charAt(i);
//            if(chr1>=19968&&chr1<=171941){//汉字范围 \u4e00-\u9fa5 (中文)
//                result+="\\u" + Integer.toHexString(chr1);
//            }else{
//                result+=str.charAt(i);
//            }
//        }
//        return result;
//    }
//
//    class myRunable2 implements Runnable {
//        protected FileOutputStream os;
//
//        public myRunable2(FileOutputStream os) {
//            this.os = os;
//        }
//
//        public void run() {
//            while (true) {
//                try {
//                    os.write(("hello" + new Date()).toString().getBytes());
//                    System.out.println("写完了。。。");
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }
//
//    class myRunable implements Runnable {
//        protected PipedOutputStream os;
//
//        public myRunable(PipedOutputStream os) {
//            this.os = os;
//        }
//
//        public void run() {
//            while (true) {
//                try {
//                    Thread.sleep(10000);
//                    os.write(("hello" + new Date()).toString().getBytes());
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }
//}
